\doxysection{bsp\+\_\+spi.\+h}
\hypertarget{bsp__spi_8h_source}{}\label{bsp__spi_8h_source}\index{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/bsp/spi/bsp\_spi.h@{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/bsp/spi/bsp\_spi.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{spi_8h}{spi.h}}"{}}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}stdint.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{gpio_8h}{gpio.h}}"{}}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{comment}{/*\ 根据开发板引出的spi引脚以及CubeMX中的初始化配置设定\ */}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ SPI\_DEVICE\_CNT\ 2\ \ \ \ \ \ \ }\textcolor{comment}{//\ C型开发板引出两路spi,分别连接BMI088/作为扩展IO在8pin牛角座引出}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#define\ MX\_SPI\_BUS\_SLAVE\_CNT\ 4\ }\textcolor{comment}{//\ 单个spi总线上挂载的从机数目}}
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{comment}{/*\ spi\ transmit\ recv\ mode\ enumerate*/}}
\DoxyCodeLine{00010\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{enum}}
\DoxyCodeLine{00011\ \{}
\DoxyCodeLine{00012\ \ \ \ \ SPI\_BLOCK\_MODE\ =\ 0,\ \textcolor{comment}{//\ 默认使用阻塞模式}}
\DoxyCodeLine{00013\ \ \ \ \ SPI\_IT\_MODE,}
\DoxyCodeLine{00014\ \ \ \ \ SPI\_DMA\_MODE,}
\DoxyCodeLine{00015\ \}\ SPI\_TXRX\_MODE\_e;}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ \textcolor{comment}{/*\ SPI实例结构体定义\ */}}
\DoxyCodeLine{00018\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{structspi__ins__temp}{spi\_ins\_temp}}}
\DoxyCodeLine{00019\ \{}
\DoxyCodeLine{00020\ \ \ \ \ \mbox{\hyperlink{group___s_p_i___exported___types_gab633e49dd034de2f3a1fe79853d78d18}{SPI\_HandleTypeDef}}\ *spi\_handle;\ \textcolor{comment}{//\ SPI外设handle}}
\DoxyCodeLine{00021\ \ \ \ \ \mbox{\hyperlink{struct_g_p_i_o___type_def}{GPIO\_TypeDef}}\ *GPIOx;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号对应的GPIO,如GPIOA,GPIOB等等}}
\DoxyCodeLine{00022\ \ \ \ \ uint16\_t\ cs\_pin;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号对应的引脚号,GPIO\_PIN\_1,GPIO\_PIN\_2等等}}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \ \ \ \ SPI\_TXRX\_MODE\_e\ spi\_work\_mode;\ \textcolor{comment}{//\ 传输工作模式}}
\DoxyCodeLine{00025\ \ \ \ \ uint8\_t\ rx\_size;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 本次接收的数据长度}}
\DoxyCodeLine{00026\ \ \ \ \ uint8\_t\ *rx\_buffer;\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 本次接收的数据缓冲区}}
\DoxyCodeLine{00027\ \ \ \ \ uint8\_t\ CS\_State;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号状态,用于中断模式下的片选控制}}
\DoxyCodeLine{00028\ \ \ \ \ uint8\_t\ *\ cs\_pin\_state;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号状态,用于中断模式下的片选控制}}
\DoxyCodeLine{00029\ \ \ \ \ void\ (*callback)(\textcolor{keyword}{struct\ }\mbox{\hyperlink{structspi__ins__temp}{spi\_ins\_temp}}\ *);\ \textcolor{comment}{//\ 接收回调函数}}
\DoxyCodeLine{00030\ \ \ \ \ \textcolor{keywordtype}{void}\ *id;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 模块指针}}
\DoxyCodeLine{00031\ \}\ SPIInstance;}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \textcolor{comment}{/*\ 接收回调函数定义,包含SPI的module按照此格式构建回调函数\ */}}
\DoxyCodeLine{00034\ \textcolor{keyword}{typedef}\ void\ (*spi\_rx\_callback)(SPIInstance\ *);}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{comment}{//\ @todo:\ 这里可以将GPIO\_TypeDef\ *GPIOx;\ uint16\_t\ cs\_pin合并为bsp\_gpio以简化代码实现}}
\DoxyCodeLine{00037\ \textcolor{comment}{/*\ SPI初始化配置,其实基本和SPIIstance一模一样,为了代码风格统一因此再次定义\ */}}
\DoxyCodeLine{00038\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct}}
\DoxyCodeLine{00039\ \{}
\DoxyCodeLine{00040\ \ \ \ \ \mbox{\hyperlink{group___s_p_i___exported___types_gab633e49dd034de2f3a1fe79853d78d18}{SPI\_HandleTypeDef}}\ *spi\_handle;\ \textcolor{comment}{//\ SPI外设handle}}
\DoxyCodeLine{00041\ \ \ \ \ \mbox{\hyperlink{struct_g_p_i_o___type_def}{GPIO\_TypeDef}}\ *GPIOx;\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号对应的GPIO,如GPIOA,GPIOB等等}}
\DoxyCodeLine{00042\ \ \ \ \ uint16\_t\ cs\_pin;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 片选信号对应的引脚号,GPIO\_PIN\_1,GPIO\_PIN\_2等等}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \ \ \ \ SPI\_TXRX\_MODE\_e\ spi\_work\_mode;\ \textcolor{comment}{//\ 传输工作模式}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \ \ \ \ spi\_rx\_callback\ callback;\ \textcolor{comment}{//\ 接收回调函数}}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keywordtype}{void}\ *id;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ 模块指针}}
\DoxyCodeLine{00048\ \}\ \mbox{\hyperlink{struct_s_p_i___init___config__s}{SPI\_Init\_Config\_s}};}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00056\ SPIInstance\ *SPIRegister(\mbox{\hyperlink{struct_s_p_i___init___config__s}{SPI\_Init\_Config\_s}}\ *conf);}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00066\ \textcolor{keywordtype}{void}\ SPITransmit(SPIInstance\ *spi\_ins,\ uint8\_t\ *ptr\_data,\ uint8\_t\ len);}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00076\ \textcolor{keywordtype}{void}\ SPIRecv(SPIInstance\ *spi\_ins,\ uint8\_t\ *ptr\_data,\ uint8\_t\ len);}
\DoxyCodeLine{00077\ }
\DoxyCodeLine{00088\ \textcolor{keywordtype}{void}\ SPITransRecv(SPIInstance\ *spi\_ins,\ uint8\_t\ *ptr\_data\_rx,\ uint8\_t\ *ptr\_data\_tx,\ uint8\_t\ len);}
\DoxyCodeLine{00089\ }
\DoxyCodeLine{00098\ \textcolor{keywordtype}{void}\ SPISetMode(SPIInstance\ *spi\_ins,\ SPI\_TXRX\_MODE\_e\ spi\_mode);}

\end{DoxyCode}
